$(function() {
	var uploadPath = $("#ctx").val() + "/resources/upload/";
	if ($('videoImgId').val()==undefined){
		upload(1);
	}
	$("#img-box1")
			.on(
					"click",
					".delPic",
					function() {
						var delId = $(this).attr('delId');
						dwrService.deleteAttach(delId);
						$('#img-box2').remove();
						var node = "<div id='img-box3'><input type='file' name='attach' id='"
								+ delId + "vi' /></div>";
						$("#img-box1").append(node);
						upload(delId);
					});
	function upload(videoImgId) {
		$('#' + videoImgId + 'vi').uploadify(
				{
					swf : $("#ctx").val()
							+ "/resources/uploadify/uploadify.swf",
					fileTypeExts : "*.jpg;*.png",
					uploader:$("#ctx").val()+"/admin/topic/upload.do",
					queueID : '000',
					fileObjName : "attach",
					formData : {
						"sid" : $("#sid").val(),
						"videoId" : String($('#videoId').val())
					},
					auto : true,
					onUploadSuccess : function(file, data, response) {
						var vi = $.parseJSON(data);
						var suc = $.ajaxCheck(vi);
						if (suc) {
							var node = "<div id='img-box2'><img src='"
									+ uploadPath + "thumbnail/"
									+ vi.obj.newName
									+ "'/> <div class='bfont delPic' delId='"
									+ vi.obj.id + "'>删除</div></div>";
							$("#img-box1").append(node);
							$("#img-box3").remove();
						}
					},
					onUploadError : function(file, errorCode, errorMsg,
							errorString) {
						alert('The file ' + file.name
								+ ' could not be uploaded: ' + errorString)
					}
				});
	}
	$('.confirm').click(function() {
		var videoName = $('#videoName').val();
		var videoTypeId = $("#videoTypeId").val();
		var id = $("#videoId").val();
		var proMessage = UE.getEditor('proMessage').getContent();
		dwrService.updateVideo(videoTypeId, videoName, proMessage,id);
		UE.getEditor('proMessage').setDisabled('fullscreen');
		$('#videoName').attr('disabled', true);
		$('#videoTypeId').attr('disabled', true);
	});
	$('.cancel').click(function() {
		UE.getEditor('proMessage').setEnabled();
		$('#videoName').attr('disabled', false);
		$('#videoTypeId').attr('disabled', false);
	});
	$('.ok').click(function() {
		var path = $("#ctx").val();
		var videoTypeId = $("#videoTypeId").val();
		window.location.replace(path + '/admin/topic/showVideo/' + videoTypeId+".do");
	});
});